"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from selenium import webdriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait


class BasePage:
    """
    与浏览器driver交互
    """

    # 构造方法
    def __init__(self, base_driver=None):
        if base_driver:
            self.driver = base_driver
        else:
            # 实例化driver
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(5)
            self.driver.maximize_window()

    def do_get(self, url):
        """打开页面"""
        self.driver.get(url)

    def do_find(self, by):
        """获取单个元素"""
        return self.driver.find_element(*by)

    def do_click(self, by):
        """获取单个元素"""
        return self.do_find(by).click()

    def do_finds(self, by):
        """获取多个元素"""
        return self.driver.find_elements(*by)

    def do_send_keys(self, value, by):
        """输入文本"""
        ele = self.do_find(by)
        ele.clear()
        ele.send_keys(value)

    def do_quit(self):
        """退出浏览器"""
        self.driver.quit()

    def wait_visible(self, locator):
        """显示等待元素可见"""
        return WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located(locator))

    def go_to_main(self):
        self.do_get("https://litemall.hogwarts.ceshiren.com/vue/index.html#/")
